/*
 * Copyright (c) 2023 Huawei Technologies Co., Ltd.
 * openUBMC is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *         http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */

#ifndef __OPTICAL_MODULE_H__
#define __OPTICAL_MODULE_H__

#include <mc/core/timer.h>
#include <mc/engine/service.h>

#include <device_tree/interface/OpticalModule.h>

#include <ncsi_over_mctp/ncsi_over_mctp_huawei.h>

namespace dev {

using ncsi_over_mctp_hw_ptr = std::shared_ptr<ncsi_over_mctp_huawei>;
class OpticalModule : public mc::engine::interface<OpticalModule, gen::OpticalModule> {
public:
    OpticalModule()  = default;
    ~OpticalModule() {
        // 释放定时器资源，防止内存泄漏
        stop_ncsi_update_task();
    }

public:
    // ncsi over mctp 华为自定义命令实现
    bool get_optical_module_info_by_ncsi();
    void start_ncsi_update_task_huawei(ncsi_over_mctp_hw_ptr ncsi_over_mctp,
                                       mc::milliseconds      interval);
    void stop_ncsi_update_task();

    void set_port_id(uint8_t port_id) {
        m_port_id = port_id;
    }

    uint8_t get_port_id() const {
        return m_port_id;
    }

private:
    ncsi_over_mctp_hw_ptr m_ncsi_over_mctp_huawei;
    mc::core::timer*      m_ncsi_timer;
    uint8_t               m_port_id;
};

} // namespace dev

#endif // OPTICAL_MODULE_H